* Mechanisms_MediaCoverage_Overleaf
** Goal: examine media coverage data
** Beatrice Lee
** Date Created: 2024-06-20
** Last Updated: 2024-07-31 // tja

cd "$Data/Processing"
use state_elections_panel_df5_20240731, clear

* summary stats
sum ratio_gub_sen if year >= 2020 & year <= 2022
sum ratio_gub_sen if year >= 2013 & year <= 2019

* scatterplots -------------------------------------

* v basic distribution plot
cd "$Charts"
hist ratio_gub_sen, legend(off) xtitle("Ratio of Stories about Inc. Gov. to Inc. Sen." "(Pre-Pandemic Elections)")

cd "$Charts"
graph export "density_plot_20240731.png", as("png") width (6000) replace

* scatterplot of results (y = ratio_gub_sen, x = lagged_ratio_gub_sen_class_spec)

cd "$Charts"
scatter ratio_gub_sen lagged_ratio_gub_sen_class_spec if year>= 2020, msize(tiny) mlabel(state) mcolor(blue) mlabcolor(black) graphregion(fcolor(white)) ytitle(,size(small)) legend(off) xtitle("Ratio of Stories about Inc. Gov. to Inc. Sen." "(Pre-Pandemic Elections)") ytitle("Ratio of Stories about Inc. Gov. to Inc. Sen." "(Pandemic Elections)") || lfit ratio_gub_sen lagged_ratio_gub_sen_class_spec if year >= 2020

cd "$Charts"
graph export "ratio_gub_sen_pre_vs_pandemic_20240731.png", as("png") width (6000) replace

* scatterplot of results (y = ratio_gub_sen, x = year)
cd "$Charts"
scatter ratio_gub_sen year if year>= 2013, msize(tiny) mlabel(state) mcolor(blue) mlabcolor(black) graphregion(fcolor(white)) ytitle(,size(small)) legend(off) xtitle("Year" "(Pre-Pandemic Elections)") ytitle("Ratio of Stories about Inc. Gov. to Inc. Sen." "(Pandemic Elections)") || lfit ratio_gub_sen year if year >= 2013

cd "$Charts"
graph export "ratio_gub_sen_pre_by_year_20240731.png", as("png") width (6000) replace

********************************************* OUTREG2 ****************************************************

* 2sls ----------------------------------------------------------
cd "$Results"
global mech1 "$Results/media_ratio_new_20240731.xls"

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? 
ivregress 2sls ratio_gub_sen norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? + lagged race-specific var
ivregress 2sls ratio_gub_sen lagged_ratio_gub_sen_class_spec norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? + lagged non-race-specific var
ivregress 2sls ratio_gub_sen lagged_ratio_gub_sen norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)

*2) panel ---------------------------------------------------------------------

cd "$Results"
global mech1 "$Results/media_ratio_panel_new_20240731.xls"

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? 

*** no controls, no fes
reg ratio_gub_sen c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)

*** normal vote, no fes
reg ratio_gub_sen norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if year > 2012 , vce(cluster state)

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
** vote share during the pandemic by including state and year fixed effects
reghdfe ratio_gub_sen norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips year)

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)

** all fes
reghdfe ratio_gub_sen norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)

outreg2 using "$mech1", append ctitle(Ratio Inc Gub: Inc Sen)


***************************************** OVER LEAF ************************************************

eststo clear

*1) 2sls ----------------------------------------------------------------------

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? 
eststo: ivregress 2sls ratio_gub_sen norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? + lagged race-specific var
eststo: ivregress 2sls ratio_gub_sen lagged_ratio_gub_sen_class_spec norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

*** Did Aid Impact Ratio of Incumbent Gub: Inc Sen Stories? + lagged non-race-specific var
eststo: ivregress 2sls ratio_gub_sen lagged_ratio_gub_sen norm_vote_top2_share_sd (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022 & office == "senate"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** Export Table to Latex
cd "$Results"
esttab using "media_coverage_20240731.tex", replace /// Replace file if it already exists
 collabels("\multicolumn{1}{c}{1l}" "\multicolumn{1}{c}{l2}" "\multicolumn{1}{c}{l3}" "\multicolumn{1}{c}{l4}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs ///
 title("Media Coverage 2sls") ///
 addnotes("Note: TKTKTKTK")

*2) panel ---------------------------------------------------------------------

eststo clear

//////////////////////// outcome 1 = ratio inc gub to inc sen stories (no lagged dep var)

*** no controls, no fes
eststo: reg ratio_gub_sen c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** normal vote, no fes
eststo: reg ratio_gub_sen norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
** vote share during the pandemic by including state and year fixed effects
eststo: reghdfe ratio_gub_sen norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips year)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe ratio_gub_sen norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

//////////////////////// outcome 1 = ratio inc gub to inc sen stories (with lagged dep var)

*** no controls, no fes
eststo: reg ratio_gub_sen lagged_ratio_gub_sen_class_spec c.reps_per_million##i.duringpandemic if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** normal vote, no fes
eststo: reg ratio_gub_sen lagged_ratio_gub_sen_class_spec norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if year > 2012 , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** vote share during the pandemic by including state and year fixed effects
eststo: reghdfe ratio_gub_sen lagged_ratio_gub_sen_class_spec norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips year)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** all fes
eststo: reghdfe ratio_gub_sen lagged_ratio_gub_sen_class_spec norm_vote_top2_share_sd c.reps_per_million##i.duringpandemic c.norm_vote_top2_share_sd#i.year if year > 2012 , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"


****** Export Table to Latex
cd "$Results/"
esttab using "media_coverage_ratio_panel_20240731_v2.tex", replace ///
 collabels("\multicolumn{1}{c}{col1}" "\multicolumn{1}{c}{col2}" "\multicolumn{1}{c}{col3}" "\multicolumn{1}{c}{col4}" "\multicolumn{1}{c}{col5}" "\multicolumn{1}{c}{col6}" "\multicolumn{1}{c}{col7}" "\multicolumn{1}{c}{col8}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 office_fe year_fe state_fe norm_vote_year_fe office_state_fe, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"Office FE"' `"Year FE"' `"State FE"' `"Normal Vote x Year FE"' `"Office x State FE"')) drop(_cons) ///
 booktabs /// 
 title("Media Coverage Ratio panel") ///
 addnotes("Note: TKTKTKTK")
